<template>
  <el-container class="merchant-layout">
    <el-header>
      <h2>商家管理</h2>
      <div class="user-info">
        <span>欢迎，商家</span>
        <el-button type="text" icon="el-icon-switch-button" @click="logout" class="logout-btn">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu router>
          <el-menu-item index="/merchant/home">
            <i class="el-icon-s-home"></i>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="/merchant/product">
            <i class="el-icon-goods"></i>
            <span>商品</span>
          </el-menu-item>
          <el-menu-item index="/merchant/order">
            <i class="el-icon-s-order"></i>
            <span>订单</span>
          </el-menu-item>
          <el-menu-item index="/merchant/profile">
            <i class="el-icon-user"></i>
            <span>我的</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'MerchantLayout',
  methods: {
    logout() {
      // 清除用户状态
      localStorage.removeItem('token');
      localStorage.removeItem('userInfo');
      // 跳转到登录页
      this.$router.push('/login');
    }
  }
}
</script>

<style scoped>
.merchant-layout {
  height: 100vh;
}
.el-header {
  background-color: #545c64;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.el-aside {
  background-color: #f2f2f2;
}
.user-info {
  display: flex;
  align-items: center;
}
.logout-btn {
  color: white;
  margin-left: 15px;
}
</style> 